use rusqlite::{Connection, Result};

fn count_records(db_path: &str) -> Result<(usize, usize, usize)> {
    let conn = Connection::open(db_path)?;
    
    // 查询notice_table表的记录数
    let notice_count: usize = conn.query_row(
        "SELECT COUNT(*) FROM notice_table",
        [],
        |row| row.get(0)
    )?;
    
    // 查询target_table表的记录数
    let target_count: usize = conn.query_row(
        "SELECT COUNT(*) FROM target_table",
        [],
        |row| row.get(0)
    )?;
    
    // 查询goods_table表的记录数
    let goods_count: usize = conn.query_row(
        "SELECT COUNT(*) FROM goods_table",
        [],
        |row| row.get(0)
    )?;
    
    Ok((notice_count, target_count, goods_count))
}

fn main() {
    println!("比较jntujy.db和jntujy11.db数据库文件...");
    println!("----------------------------------------");
    
    // 获取jntujy.db的记录数
    match count_records("jntujy.db") {
        Ok((notice_count, target_count, goods_count)) => {
            println!("jntujy.db 记录数：");
            println!("  notice_table: {}", notice_count);
            println!("  target_table: {}", target_count);
            println!("  goods_table: {}", goods_count);
            println!("  总记录数: {}", notice_count + target_count + goods_count);
        },
        Err(e) => println!("查询jntujy.db失败: {}", e)
    }
    
    println!("----------------------------------------");
    
    // 获取jntujy11.db的记录数
    match count_records("jntujy11.db") {
        Ok((notice_count, target_count, goods_count)) => {
            println!("jntujy11.db 记录数：");
            println!("  notice_table: {}", notice_count);
            println!("  target_table: {}", target_count);
            println!("  goods_table: {}", goods_count);
            println!("  总记录数: {}", notice_count + target_count + goods_count);
        },
        Err(e) => println!("查询jntujy11.db失败: {}", e)
    }
}